class Solution(object):
    def removeInterval(self, intervals, toBeRemoved):
        """
        :type intervals: List[List[int]]
        :type toBeRemoved: List[int]
        :rtype: List[List[int]]
        """
        n = len(intervals)
        out = []
        for i in range(n):
            if intervals[i][1] <= toBeRemoved[0]:
                out.append(intervals[i])
            else:
                if intervals[i][0] >= toBeRemoved[1]:
                    out.append(intervals[i])
                else:
                    if intervals[i][0] < toBeRemoved[0]:
                        out.append([intervals[i][0], toBeRemoved[0]])
                    if intervals[i][1] > toBeRemoved[1]:
                        out.append([toBeRemoved[1], intervals[i][1]])
        return out


data = Solution()
intervals = [[0, 2], [3, 4], [5, 7]]
toBeRemoved = [1, 6]
print(data.removeInterval(intervals, toBeRemoved))
intervals = [[0, 5]]
toBeRemoved = [2, 3]
print(data.removeInterval(intervals, toBeRemoved))
intervals = [[-5, -4], [-3, -2], [1, 2], [3, 5], [8, 9]]
toBeRemoved = [-1, 4]
print(data.removeInterval(intervals, toBeRemoved))
